<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    class Creater{
        constructor(list) {
            this.list = list
        }
        look(){
            console.log(this)
        }
        createrIterator(){
            return new Interator(this)
        }
    }
    class Interator{
        constructor(creater) {
            this.list = creater.list
            this.index = 0
        }
        isDone(){
            if(this.index >= this.list.length){
                return true
            }
            return false
        }
        next(){
            return this.list[this.index++]
        }
    }
    let arr = [1, 2, 3, 4]
    let creater = new Creater(arr)
    console.log(creater)
    let iterator = creater.createrIterator()
    console.log(iterator,iterator.list)  // [1, 2, 3, 4]
    while(!iterator.isDone()){
        console.log(iterator.next())
    }
</script>

</body>
</html>
